import { http } from "@/utils/http";
import { PageParams, CommonResponse } from "./common";


/**
 * 角色列表返回数据格式
 */
export type RoleListResponse = {
  records: {
    id: number;
    roleName: string;
    createBy: string;
    gmtCreate: Date;
  }[]
  total: number;
  pageNum: number;
  pageSize: number
};

/**
 * 分页查询角色列表
 */
export const queryRoleList = (data: PageParams) => {
  return http.request<CommonResponse<RoleListResponse>>("post", "/api/platform/role/page", { data });
}

/**
 * 新增角色
 */
export const addRoleSubmit = (data: { roleName: string; }) => {
  return http.request<CommonResponse<number>>("post", "/api/platform/role/create", { data });
}

/**
 * 获取角色权限
 */
export const getRolePermission = (roleId: number) => {
  return http.request<CommonResponse<string[]>>("get", `/api/platform/role/${roleId}/permissions`);
}

/**
 * 设置角色权限
 */
export const setRolePermission = (data: { roleId: string; permissions: number[]; }) => {
  return http.request<CommonResponse<number>>("post", "/api/platform/role/permission/set", { data });
}

/**
 * 更新角色状态
 */
export const updateRoleStatus = (data: { roleId: number; status: number; }) => {
  return http.request<CommonResponse<number>>("post", "/api/platform/role/status/update", { data });
}

export type Permission = {
  code: string;
  description: string;
}

/**
 * 获取所有权限列表
 */
export const getAllPermissionList = () => {
  return http.request<CommonResponse<Permission[]>>("get", "/api/platform/role/permissions");
}